{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "97645c6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a7d4d131",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor(1, shape=(), dtype=int32)\n",
      "1\n",
      "tf.Tensor(2, shape=(), dtype=int32)\n",
      "2\n",
      "tf.Tensor(3, shape=(), dtype=int32)\n",
      "3\n",
      "tf.Tensor(4, shape=(), dtype=int32)\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "dataset=tf.data.Dataset.from_tensor_slices([1,2,3,4])\n",
    "for ele in dataset:\n",
    "    print(ele)\n",
    "    print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "f74850c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor([1 2], shape=(2,), dtype=int32)\n",
      "[1 2]\n",
      "tf.Tensor([3 4], shape=(2,), dtype=int32)\n",
      "[3 4]\n"
     ]
    }
   ],
   "source": [
    "dataset=tf.data.Dataset.from_tensor_slices([[1,2],[3,4]])\n",
    "for ele in dataset:\n",
    "    print(ele)\n",
    "    print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "99d9757b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'4': <tf.Tensor: shape=(), dtype=int32, numpy=1>, '5': <tf.Tensor: shape=(), dtype=int32, numpy=2>}\n",
      "{'4': <tf.Tensor: shape=(), dtype=int32, numpy=2>, '5': <tf.Tensor: shape=(), dtype=int32, numpy=4>}\n"
     ]
    }
   ],
   "source": [
    "dataset=tf.data.Dataset.from_tensor_slices({'4':[1,2],'5':[2,4]})\n",
    "for ele in dataset:\n",
    "    print(ele)\n",
    "    #print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "5d048b8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<TensorSliceDataset shapes: {4: (), 5: ()}, types: {4: tf.int32, 5: tf.int32}>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "c18c1dc9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor(1, shape=(), dtype=int64)\n",
      "tf.Tensor(2, shape=(), dtype=int64)\n"
     ]
    }
   ],
   "source": [
    "dataset=tf.data.Dataset.from_tensor_slices(np.array([1,2,3,4,5,6,7,8]))\n",
    "for ele in dataset.take(2):\n",
    "    print(ele)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "797c0101",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor(2, shape=(), dtype=int64)\n",
      "tf.Tensor(3, shape=(), dtype=int64)\n",
      "tf.Tensor(1, shape=(), dtype=int64)\n",
      "tf.Tensor(8, shape=(), dtype=int64)\n",
      "tf.Tensor(6, shape=(), dtype=int64)\n",
      "tf.Tensor(4, shape=(), dtype=int64)\n",
      "tf.Tensor(5, shape=(), dtype=int64)\n",
      "tf.Tensor(7, shape=(), dtype=int64)\n"
     ]
    }
   ],
   "source": [
    "dataset=dataset.shuffle(5)\n",
    "for ele in dataset:\n",
    "    print(ele)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "994238c5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "2\n",
      "4\n",
      "6\n",
      "7\n",
      "3\n",
      "8\n",
      "1\n",
      "5\n",
      "2\n",
      "7\n",
      "6\n",
      "4\n",
      "1\n",
      "8\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "dataset=dataset.repeat(count=2)\n",
    "for ele in dataset:\n",
    "    print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "cf6389a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 6]\n",
      "[5 1]\n",
      "[3 7]\n",
      "[8 4]\n",
      "[3 4]\n",
      "[6 2]\n",
      "[5 8]\n",
      "[7 1]\n"
     ]
    }
   ],
   "source": [
    "dataset=dataset.batch(2)\n",
    "for ele in dataset:\n",
    "    print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "9a639035",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "9\n",
      "16\n",
      "25\n",
      "36\n",
      "49\n",
      "64\n"
     ]
    }
   ],
   "source": [
    "dataset=tf.data.Dataset.from_tensor_slices(np.array([1,2,3,4,5,6,7,8]))\n",
    "dataset=dataset.map(tf.square)\n",
    "for ele in dataset:\n",
    "    print(ele.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e075347e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "750f2cb1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
